<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

    <el-table v-loading="loading" :data="controlcenterList" >
      <el-table-column label="设备" align="center" prop="deviceDesc" />
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="turnOn(scope.row)"
          >开</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="turnOff(scope.row)"
          >关</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改控制中心对话框
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
  import { listControlcenter, turnOn, turnOff } from "@/api/business/controlcenter";

  export default {
  name: "Controlcenter",
  components: {  },
  data() {
    return {
      // 遮罩层
      loading: true,

      // 总条数
      total: 0,
      // 控制中心表格数据
      controlcenterList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询控制中心列表 */
    getList() {
      this.loading = true;
      listControlcenter(this.queryParams).then(response => {
        this.controlcenterList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    turnOn(row) {
      let data = {
        index: row.gpio,
        mac: row.mac
      };
      turnOn(data).then(response => {
        if(response.code == 200) {
          this.$alert("已打开");
        } else {
          this.$alert("打开失败");
        }

      });
    },
    turnOff(row) {
      let data = {
        index: row.gpio,
        mac: row.mac
      };
      turnOff(data).then(response => {
        if(response.code == 200) {
          this.$alert("已关闭");
        } else {
          this.$alert("关闭失败");
        }

      });

    },


  }
};
</script>
